<template>
  <el-menu
      :default-active="this.$route.path.lastIndexOf('/')!=0?
                                  this.$route.path.substring(0,this.$route.path.indexOf('/',1)):
                                  this.$route.path"
      class="el-menu-vertical-demo"
      :unique-opened="true"
      :collapse="isCollapse"
      router>
    <el-header height="250px" style="padding: 0px 0px;">
      <el-avatar id="logo" shape="squre" :size="160" :src="logo"
                 style="margin-top:50px;background-color: rgba(255,255,255,0);" v-if="isCollapse==0"
                 :key="isCollapse"></el-avatar>
    </el-header>
    <el-menu-item index="/dataPage">
      <i class="el-icon-star-off"></i>

      <span slot="title">首页</span>
    </el-menu-item>

    <el-submenu index="/user">
      <template slot="title">
        <i class="el-icon-coin"></i>
        <span>用户系统</span>
      </template>
      <el-menu-item index="/userPage" v-if="user.userRole=='admin'">
        <i class="el-icon-user"></i>
        <span slot="title">用户管理</span>
      </el-menu-item>
      <el-menu-item index="/tokenPage" v-if="user.userRole=='admin'">
        <i class="el-icon-user"></i>
        <span slot="title">Token管理</span>
      </el-menu-item>
      <el-menu-item index="/rolePage" v-if="user.userRole=='admin'">
        <i class="el-icon-user"></i>
        <span slot="title">角色管理</span>
      </el-menu-item>
    </el-submenu>
    <!--      <el-menu-item index="/userSetting">-->
    <!--        <i class="el-icon-setting"></i>-->
    <!--        <span slot="title">账号设置</span>-->
    <!--      </el-menu-item>-->
    <!--      任务子导航：任务列表和任务模板列表-->
    <!--      sub-->


    <!--    系统配置 子目录-->
    <el-submenu index="setting" v-if="user.userRole=='admin'||user.userRole=='dev'">
      <template slot="title">
        <i class="el-icon-setting"></i>
        <span slot="title">系统配置</span>
      </template>
      <el-menu-item index="/settingPage" v-if="user.userRole=='admin'">
        <i class="el-icon-set-up"></i>
        <span slot="title">站点设置</span>
      </el-menu-item>
      <el-menu-item index="/loginfo" v-if="user.userRole=='admin'||user.userRole=='dev'">
        <i class="el-icon-notebook-1"></i>
        <span slot="title">日志查看</span>
      </el-menu-item>
      <el-menu-item index="/authPage" v-if="user.userRole=='admin'||user.userRole=='dev'">
        <i class="el-icon-set-up"></i>
        <span slot="title">接口鉴权管理</span>
      </el-menu-item>
    </el-submenu>
    <el-menu-item @click.native="logout()">
      <i class="el-icon-switch-button"></i>
      <span slot="title">用户退出</span>
    </el-menu-item>
    <!--      <el-menu-item>-->


    <!--      </el-menu-item>-->
    <div>

      <globel-footer v-if="isCollapse==0" :key="isCollapse"></globel-footer>
    </div>
  </el-menu>

</template>

<script>


// import {userApi} from "@/core/api/user";
import {SiteApi} from "@/core/request/api/SiteApi";
import {AuthApi} from "@/core/request/api/AuthApi";
import GlobelFooter from "@/components/globelFooter";
import {userApi} from "@/core/request/api/UserApi";


export default {
  name: "manggerLefter",
  components: {GlobelFooter},
  props: {
    isCollapse: null
  },
  data() {
    return {
      logo: null,
      user: JSON.parse(sessionStorage.getItem("loginStatus")),
    }
  },
  computed: {},
  methods: {


    logout() {
      this.axios.post(userApi.sysLogout).then(res => {
          this.$store.dispatch("setToken")
          sessionStorage.removeItem('loginStatus')
        if (!res.data.code) {
          this.$message.success(res.data.message)
        } else{
          this.$message.error(res.data.message)
        }
          this.$router.go(0)
      })
    },
    routeReload() {
      this.axios.get(AuthApi.reload)
          .then(response => {
            var res = response.data
            if (!res.code) {
              this.$message.success(res.message)
            } else this.$message.error(res.message)
          })
          .catch(err => {
            this.$message.info(err.data.message)
          })
    }
  },
  mounted() {
    this.axios.get(SiteApi.getAttributeByCommon + 'siteLogo')
        .then(res => {
          if (!res.data.code) {
            this.logo = res.data.data
          }
        })
  }
}
</script>

<style scoped>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  text-align: center;
}

.el-menu-vertical-demo {
  height: 100vh;
}

/*.el-icon-arrow-right{*/
/*  display: none;*/
/*}*/

/*#logo{*/
/*  margin-top: 50px;*/
/*}*/
</style>

